home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / REGSETUP.PY < prev    next >
Encoding:
Python Source  |  1998-07-15  |  21.0 KB  |  590 lines

  1. # A tool to setup the Python registry.
  2.  
  3. error = "Registry Setup Error"
  4.  
  5. import sys # at least we can count on this!
  6.  
  7. def FileExists(fname):
  8.     """Check if a file exists.  Returns true or false.
  9.     """
  10.     import os
  11.     try:
  12.         os.stat(fname)
  13.         return 1
  14.     except os.error, details:
  15.         return 0
  16.  
  17. def IsPackageDir(path, packageName, knownFileName):
  18.     """Given a path, a ni package name, and possibly a known file name in
  19.            the root of the package, see if this path is good.
  20.       """
  21.     import os
  22.     if knownFileName is None:
  23.         knownFileName = "."
  24.     return FileExists(os.path.join(os.path.join(path, packageName),knownFileName))
  25.  
  26.  
  27. def FindPackagePath(packageName, knownFileName, searchPaths):
  28.     """Find a package.
  29.  
  30.            Given a ni style package name, check the package is registered.
  31.  
  32.            First place looked is the registry for an existing entry.  Then
  33.            the searchPaths are searched.
  34.       """
  35.     import win32api, win32con, regutil
  36.     pathLook = regutil.GetRegisteredNamedPath(packageName)
  37.     if pathLook and IsPackageDir(pathLook, packageName, knownFileName):
  38.         return pathLook, None # The currently registered one is good.
  39.     # Search down the search paths.
  40.     for pathLook in searchPaths:
  41.         if IsPackageDir(pathLook, packageName, knownFileName):
  42.             # Found it
  43.             ret = win32api.GetFullPathName(pathLook)
  44.             return ret, ret
  45.     raise error, "The package %s can not be located" % packageName
  46.  
  47. def FindHelpPath(helpFile, helpDesc, searchPaths):
  48.     # See if the current registry entry is OK
  49.     import win32api, win32con, os
  50.     try:
  51.         key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Help", 0, win32con.KEY_ALL_ACCESS)
  52.         try:
  53.             try:
  54.                 path = win32api.RegQueryValueEx(key, helpDesc)[0]
  55.                 print "Looking in", path
  56.                 if FileExists(os.path.join(path, helpFile)):
  57.                     return win32api.GetFullPathName(path)
  58.             except win32api.error:
  59.                 pass # no registry entry.
  60.         finally:
  61.             win32api.RegCloseKey(key)
  62.     except win32api.error:
  63.         pass
  64.     for pathLook in searchPaths:
  65.         if FileExists(os.path.join(pathLook, helpFile)):
  66.             return win32api.GetFullPathName(pathLook)
  67.         pathLook = os.path.join(pathLook, "Help")
  68.         if FileExists(os.path.join( pathLook, helpFile)):
  69.             return win32api.GetFullPathName(pathLook)
  70.     raise error, "The help file %s can not be located" % helpFile
  71.  
  72. def FindAppPath(appName, knownFileName, searchPaths):
  73.     """Find an application.
  74.  
  75.          First place looked is the registry for an existing entry.  Then
  76.          the searchPaths are searched.
  77.       """
  78.     # Look in the first path.
  79.     import win32api, win32con, regutil, string, os
  80.     regPath = regutil.GetRegisteredNamedPath(appName)
  81.     if regPath:
  82.         pathLook = string.split(regPath,";")[0]
  83.     if regPath and FileExists(os.path.join(pathLook, knownFileName)):
  84.         return None # The currently registered one is good.
  85.     # Search down the search paths.
  86.     for pathLook in searchPaths:
  87.         if FileExists(os.path.join(pathLook, knownFileName)):
  88.             # Found it
  89.             return win32api.GetFullPathName(pathLook)
  90.     raise error, "The file %s can not be located for application %s" % (knownFileName, appName)
  91.  
  92. def FindRegisteredModule(moduleName, possibleRealNames, searchPaths):
  93.     """Find a registered module.
  94.  
  95.          First place looked is the registry for an existing entry.  Then
  96.          the searchPaths are searched.
  97.          
  98.        Returns the full path to the .exe or None if the current registered entry is OK.
  99.       """
  100.     import win32api, win32con, regutil, string
  101.     try:
  102.         fname = win32api.RegQueryValue(regutil.GetRootKey(), \
  103.                        regutil.BuildDefaultPythonKey() + "\\Modules\\%s" % moduleName)
  104.  
  105.         if FileExists(fname):
  106.             return None # Nothing extra needed
  107.  
  108.     except win32api.error:
  109.         pass
  110.     return LocateFileName(possibleRealNames, searchPaths)
  111.  
  112. def FindPythonExe(exeAlias, possibleRealNames, searchPaths):
  113.     """Find an exe.
  114.  
  115.          First place looked is the registry for an existing entry.  Then
  116.          the searchPaths are searched.
  117.          
  118.        Returns the full path to the .exe, and a boolean indicating if the current 
  119.        registered entry is OK.
  120.       """
  121.     import win32api, win32con, regutil, string
  122.     if possibleRealNames is None:
  123.         possibleRealNames = exeAlias
  124.     try:
  125.         fname = win32api.RegQueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exeAlias)
  126.         if FileExists(fname):
  127.             return fname, 1 # Registered entry OK
  128.  
  129.     except win32api.error:
  130.         pass
  131.     return LocateFileName(possibleRealNames, searchPaths), 0
  132.  
  133. def QuotedFileName(fname):
  134.     """Given a filename, return a quoted version if necessary
  135.       """
  136.     import win32api, win32con, regutil, string
  137.     try:
  138.         string.index(fname, " ") # Other chars forcing quote?
  139.         return '"%s"' % fname
  140.     except ValueError:
  141.         # No space in name.
  142.         return fname
  143.  
  144. def LocateFileName(fileNamesString, searchPaths):
  145.     """Locate a file name, anywhere on the search path.
  146.  
  147.        If the file can not be located, prompt the user to find it for us
  148.        (using a common OpenFile dialog)
  149.  
  150.        Raises KeyboardInterrupt if the user cancels.
  151.     """
  152.     import win32api, win32con, regutil, string, os
  153.     fileNames = string.split(fileNamesString,";")
  154.     for path in searchPaths:
  155.         for fileName in fileNames:
  156.             try:
  157.                 retPath = os.path.join(path, fileName)
  158.                 os.stat(retPath)
  159.                 break
  160.             except os.error:
  161.                 retPath = None
  162.         if retPath:
  163.             break
  164.     else:
  165.         fileName = fileNames[0]
  166.         try:
  167.             import win32ui
  168.         except ImportError:
  169.             raise error, "Need to locate the file %s, but the win32ui module is not available\nPlease run the program again, passing as a parameter the path to this file." % fileName
  170.         # Display a common dialog to locate the file.
  171.         flags=win32con.OFN_FILEMUSTEXIST
  172.         ext = os.path.splitext(fileName)[1]
  173.         filter = "Files of requested type (*%s)|*%s||" % (ext,ext)
  174.         dlg = win32ui.CreateFileDialog(1,None,fileName,flags,filter,None)
  175.         dlg.SetOFNTitle("Locate " + fileName)
  176.         if dlg.DoModal() <> win32con.IDOK:
  177.             raise KeyboardInterrupt, "User cancelled the process"
  178.         retPath = dlg.GetPathName()
  179.     return win32api.GetFullPathName(retPath)
  180.  
  181. def LocatePath(fileName, searchPaths):
  182.     """Like LocateFileName, but returns a directory only.
  183.     """
  184.     import os, win32api
  185.     return win32api.GetFullPathName(os.path.split(LocateFileName(fileName, searchPaths))[0])
  186.  
  187. def LocateOptionalPath(fileName, searchPaths):
  188.     """Like LocatePath, but returns None if the user cancels.
  189.     """
  190.     try:
  191.         return LocatePath(fileName, searchPaths)
  192.     except KeyboardInterrupt:
  193.         return None
  194.  
  195.  
  196. def LocateOptionalFileName(fileName, searchPaths = None):
  197.     """Like LocateFileName, but returns None if the user cancels.
  198.     """
  199.     try:
  200.         return LocateFileName(fileName, searchPaths)
  201.     except KeyboardInterrupt:
  202.         return None
  203.  
  204. def LocatePythonCore(searchPaths):
  205.     """Locate and validate the core Python directories.  Returns a list
  206.          of paths that should be used as the core (ie, un-named) portion of
  207.          the Python path.
  208.     """
  209.     import win32api, win32con, string, os, regutil
  210.     currentPath = regutil.GetRegisteredNamedPath(None)
  211.     if currentPath:
  212.         presearchPaths = string.split(currentPath, ";")
  213.     else:
  214.         presearchPaths = [win32api.GetFullPathName(".")]
  215.     libPath = None
  216.     for path in presearchPaths:
  217.         if FileExists(os.path.join(path, "os.py")):
  218.             libPath = path
  219.             break
  220.     if libPath is None and searchPaths is not None:
  221.         libPath = LocatePath("os.py", searchPaths)
  222.     if libPath is None:
  223.         raise error, "The core Python library could not be located."
  224.  
  225.     corePath = None
  226.     for path in presearchPaths:
  227.         if FileExists(os.path.join(path, "parser.dll")):
  228.             corePath = path
  229.             break
  230.     if corePath is None and searchPaths is not None:
  231.         corePath = LocatePath("parser.dll", searchPaths)
  232.     if corePath is None:
  233.         raise error, "The core Python path could not be located."
  234.  
  235.     installPath = win32api.GetFullPathName(os.path.join(libPath, ".."))
  236.     return installPath, [libPath, corePath]
  237.  
  238. def FindRegisterPackage(packageName, knownFile, searchPaths):
  239.     """Find and Register a package.
  240.  
  241.        Assumes the core registry setup correctly.
  242.  
  243.        In addition, if the location located by the package is already
  244.            in the **core** path, then an entry is registered, but no path.
  245.        (no other paths are checked, as the application whose path was used
  246.        may later be uninstalled.  This should not happen with the core)
  247.     """
  248.     import win32api, win32con, regutil, string
  249.     if not packageName: raise error, "A package name must be supplied"
  250.     corePaths = string.split(regutil.GetRegisteredNamedPath(None),";")
  251.     if not searchPaths: searchPaths = corePaths
  252.     try:
  253.         pathLook, pathAdd = FindPackagePath(packageName, knownFile, searchPaths)
  254.         if pathAdd is not None:
  255.             if pathAdd in corePaths:
  256.                 pathAdd = ""
  257.             regutil.RegisterNamedPath(packageName, pathAdd)
  258.         return pathLook
  259.     except error, details:
  260.         print "*** The %s package could not be registered - %s" % (packageName, details)
  261.         print "*** Please ensure you have passed the correct paths on the command line."
  262.         print "*** - For packages, you should pass a path to the packages parent directory,"
  263.         print "*** - and not the package directory itself..."
  264.  
  265.  
  266. def FindRegisterApp(appName, knownFiles, searchPaths):
  267.     """Find and Register a package.
  268.  
  269.        Assumes the core registry setup correctly.
  270.  
  271.     """
  272.     import win32api, win32con, regutil, string
  273.     if type(knownFiles)==type(''):
  274.         knownFiles = [knownFiles]
  275.     paths=[]
  276.     try:
  277.         for knownFile in knownFiles:
  278.             pathLook = FindAppPath(appName, knownFile, searchPaths)
  279.             if pathLook:
  280.                 paths.append(pathLook)
  281.     except error, details:
  282.         print "*** ", details
  283.         return
  284.  
  285.     regutil.RegisterNamedPath(appName, string.join(paths,";"))
  286.  
  287. def FindRegisterModule(modName, actualFileNames, searchPaths):
  288.     """Find and Register a module.
  289.  
  290.        Assumes the core registry setup correctly.
  291.     """
  292.     import regutil
  293.     try:
  294.         fname = FindRegisteredModule(modName, actualFileNames, searchPaths)
  295.         if fname is not None:
  296.             regutil.RegisterModule(modName, fname)
  297.     except error, details:
  298.         print "*** ", details
  299.  
  300. def FindRegisterPythonExe(exeAlias, searchPaths, actualFileNames = None):
  301.     """Find and Register a Python exe (not necessarily *the* python.exe)
  302.  
  303.        Assumes the core registry setup correctly.
  304.     """
  305.     import win32api, win32con, regutil, string
  306.     fname, ok = FindPythonExe(exeAlias, actualFileNames, searchPaths)
  307.     if not ok:
  308.         regutil.RegisterPythonExe(fname, exeAlias)
  309.     return fname
  310.  
  311.  
  312. def FindRegisterHelpFile(helpFile, searchPaths, helpDesc = None ):
  313.     import regutil
  314.     
  315.     try:
  316.         pathLook = FindHelpPath(helpFile, helpDesc, searchPaths)
  317.     except error, details:
  318.         print "*** ", details
  319.         return
  320. #    print "%s found at %s" % (helpFile, pathLook)
  321.     regutil.RegisterHelpFile(helpFile, pathLook, helpDesc)
  322.     
  323. def SetupCore(searchPaths):
  324.     """Setup the core Python information in the registry.
  325.  
  326.        This function makes no assumptions about the current state of sys.path.
  327.  
  328.        After this function has completed, you should have access to the standard
  329.        Python library, and the standard Win32 extensions
  330.     """
  331.  
  332.     import sys    
  333.     for path in searchPaths:
  334.         sys.path.append(path)
  335.  
  336.     import string, os
  337.     import regutil, win32api, win32con
  338.     
  339.     installPath, corePaths = LocatePythonCore(searchPaths)
  340.     # Register the core Pythonpath.
  341.     print corePaths
  342.     regutil.RegisterNamedPath(None, string.join(corePaths,";"))
  343.  
  344.     # Register the install path.
  345.     hKey = win32api.RegCreateKey(regutil.GetRootKey() , regutil.BuildDefaultPythonKey())
  346.     try:
  347.         # Core Paths.
  348.         win32api.RegSetValue(hKey, "InstallPath", win32con.REG_SZ, installPath)
  349.     finally:
  350.         win32api.RegCloseKey(hKey)
  351.     # The core DLL.
  352.     regutil.RegisterCoreDLL()
  353.  
  354.     # Register the win32 extensions, as some of them are pretty much core!
  355.     # Why doesnt win32con.__file__ give me a path? (ahh - because only the .pyc exists?)
  356.  
  357.     # Register the win32 core paths.
  358.     win32paths = win32api.GetFullPathName( os.path.split(win32api.__file__)[0]) + ";" + \
  359.                  win32api.GetFullPathName( os.path.split(LocateFileName("win32con.py;win32con.pyc", sys.path ) )[0] )
  360.                  
  361.     FindRegisterModule("pywintypes", "pywintypes15.dll", [".", win32api.GetSystemDirectory()])
  362.     regutil.RegisterNamedPath("win32",win32paths)
  363.  
  364.  
  365. def RegisterShellInfo(searchPaths):
  366.     """Registers key parts of the Python installation with the Windows Shell.
  367.  
  368.        Assumes a valid, minimal Python installation exists
  369.        (ie, SetupCore() has been previously successfully run)
  370.     """
  371.     import regutil, win32con
  372.     # Set up a pointer to the .exe's
  373.     exePath = FindRegisterPythonExe("Python.exe", searchPaths)
  374.     regutil.SetRegistryDefaultValue(".py", "Python.File", win32con.HKEY_CLASSES_ROOT)
  375.     regutil.RegisterShellCommand("Open", QuotedFileName(exePath)+" %1 %*", "&Run")
  376.     regutil.SetRegistryDefaultValue("Python.File\\DefaultIcon", "%s,0" % exePath, win32con.HKEY_CLASSES_ROOT)
  377.     
  378.     FindRegisterHelpFile("Python.hlp", searchPaths, "Main Python Documentation")
  379.  
  380.     # We consider the win32 core, as it contains all the win32 api type
  381.     # stuff we need.
  382. #    FindRegisterApp("win32", ["win32con.pyc", "win32api.pyd"], searchPaths)
  383.  
  384. def RegisterPythonwin(searchPaths):
  385.     """Knows how to register Pythonwin components
  386.     """
  387.     import regutil
  388.     FindRegisterApp("Pythonwin", "docview.py", searchPaths)
  389.     FindRegisterHelpFile("Pythonwin.hlp", searchPaths, "Pythonwin Reference")
  390.     
  391.     FindRegisterPythonExe("pythonwin.exe", searchPaths, "Pythonwin.exe")
  392.     regutil.RegisterShellCommand("Edit", QuotedFileName("pythonwin.exe")+" /edit %1")
  393.     regutil.RegisterDDECommand("Edit", "Pythonwin", "System", '[self.OpenDocumentFile(r"%1")]')
  394.  
  395.     FindRegisterModule("win32ui", "win32ui.pyd", searchPaths)
  396.     FindRegisterModule("win32uiole", "win32uiole.pyd", searchPaths)
  397.  
  398.     fnamePythonwin = regutil.GetRegisteredExe("Pythonwin.exe")
  399.     fnamePython = regutil.GetRegisteredExe("Python.exe")
  400.     
  401.     regutil.RegisterFileExtensions(defPyIcon=fnamePythonwin+",0", 
  402.                                    defPycIcon = fnamePythonwin+",5",
  403.                                    runCommand = QuotedFileName(fnamePython)+" %1 %*")
  404.  
  405. def UnregisterPythonwin():
  406.     """Knows how to unregister Pythonwin components
  407.     """
  408.     import regutil
  409.     regutil.UnregisterNamedPath("Pythonwin")
  410.     regutil.UnregisterHelpFile("Pythonwin.hlp")
  411.  
  412.     regutil.UnregisterPythonExe("pythonwin.exe")
  413.     
  414.     #regutil.UnregisterShellCommand("Edit")
  415.  
  416.     regutil.UnregisterModule("win32ui")
  417.     regutil.UnregisterModule("win32uiole")
  418.     
  419.  
  420. def RegisterWin32com(searchPaths):
  421.     """Knows how to register win32com components
  422.     """
  423.     import win32api
  424. #    import ni,win32dbg;win32dbg.brk()
  425.     corePath = FindRegisterPackage("win32com", "olectl.py", searchPaths)
  426.     if corePath:
  427.         FindRegisterHelpFile("win32com.hlp", searchPaths + [corePath+"\\win32com"], "Python COM Reference")
  428.         FindRegisterModule("pythoncom", "pythoncom15.dll", [win32api.GetSystemDirectory(), '.'])
  429.  
  430. usage = """\
  431. regsetup.py - Setup/maintain the registry for Python apps.
  432.  
  433. Run without options, (but possibly search paths) to repair a totally broken
  434. python registry setup.  This should allow other options to work.
  435.  
  436. Usage:   %s [options ...] paths ...
  437. -p packageName  -- Find and register a package.  Looks in the paths for
  438.                    a sub-directory with the name of the package, and
  439.                    adds a path entry for the package.
  440. -a appName      -- Unconditionally add an application name to the path.
  441.                    A new path entry is create with the app name, and the
  442.                    paths specified are added to the registry.
  443. -c              -- Add the specified paths to the core Pythonpath.
  444.                    If a path appears on the core path, and a package also 
  445.                    needs that same path, the package will not bother 
  446.                    registering it.  Therefore, By adding paths to the 
  447.                    core path, you can avoid packages re-registering the same path.  
  448. -m filename     -- Find and register the specific file name as a module.
  449.                    Do not include a path on the filename!
  450. --shell         -- Register everything with the Win95/NT shell.
  451. --pythonwin     -- Find and register all Pythonwin components.
  452. --unpythonwin   -- Unregister Pythonwin
  453. --win32com      -- Find and register all win32com components
  454. --upackage name -- Unregister the package
  455. --uapp name     -- Unregister the app (identical to --upackage)
  456. --umodule name  -- Unregister the module
  457.  
  458. --description   -- Print a description of the usage.
  459. --examples      -- Print examples of usage.
  460. """ % sys.argv[0]
  461.  
  462. description="""\
  463. If no options are processed, the program attempts to validate and set 
  464. the standard Python path to the point where the standard library is
  465. available.  This can be handy if you move Python to a new drive/sub-directory,
  466. in which case most of the options would fail (as they need at least string.py,
  467. os.py etc to function.)
  468. Running without options should repair Python well enough to run with 
  469. the other options.
  470.  
  471. paths are search paths that the program will use to seek out a file.
  472. For example, when registering the core Python, you may wish to
  473. provide paths to non-standard places to look for the Python help files,
  474. library files, etc.  When registering win32com, you should pass paths
  475. specific to win32com.
  476.  
  477. See also the "regcheck.py" utility which will check and dump the contents
  478. of the registry.
  479. """
  480.  
  481. examples="""\
  482. Examples:
  483. "regsetup c:\\wierd\\spot\\1 c:\\wierd\\spot\\2"
  484. Attempts to setup the core Python.  Looks in some standard places,
  485. as well as the 2 wierd spots to locate the core Python files (eg, Python.exe,
  486. python14.dll, the standard library and Win32 Extensions.
  487.  
  488. "regsetup --win32com"
  489. Attempts to register win32com.  No options are passed, so this is only
  490. likely to succeed if win32com is already successfully registered, or the
  491. win32com directory is current.  If neither of these are true, you should pass
  492. the path to the win32com directory.
  493.  
  494. "regsetup -a myappname . .\subdir"
  495. Registers a new Pythonpath entry named myappname, with "C:\\I\\AM\\HERE" and
  496. "C:\\I\\AM\\HERE\subdir" added to the path (ie, all args are converted to
  497. absolute paths)
  498.  
  499. "regsetup -c c:\\my\\python\\files"
  500. Unconditionally add "c:\\my\\python\\files" to the 'core' Python path.
  501.  
  502. "regsetup -m some.pyd \\windows\\system"
  503. Register the module some.pyd in \\windows\\system as a registered
  504. module.  This will allow some.pyd to be imported, even though the
  505. windows system directory is not (usually!) on the Python Path.
  506.  
  507. "regsetup --umodule some"
  508. Unregister the module "some".  This means normal import rules then apply
  509. for that module.
  510. """
  511.  
  512. if __name__=='__main__':
  513.     if len(sys.argv)>1 and sys.argv[1] in ['/?','-?','-help','-h']:
  514.         print usage
  515.     elif len(sys.argv)==1 or not sys.argv[1][0] in ['/','-']:
  516.         # No args, or useful args.
  517.         searchPath = sys.path[:]
  518.         for arg in sys.argv[1:]:
  519.             searchPath.append(arg)
  520.         # Good chance we are being run from the "regsetup.py" directory.
  521.         # Typically this will be "\somewhere\win32\lib" and the "somewhere"
  522.         # should also be searched.
  523.         searchPath.append("..\\..")
  524.         print "Attempting to setup/repair the Python core"
  525.         
  526.         SetupCore(searchPath)
  527.         RegisterShellInfo(searchPath)    
  528.         # Check the registry.
  529.         print "Registration complete - checking the registry..."
  530.         import regcheck
  531.         regcheck.CheckRegistry()
  532.     else:
  533.         searchPaths = []
  534.         import getopt, string
  535.         opts, args = getopt.getopt(sys.argv[1:], 'p:a:m:c', 
  536.             ['pythonwin','unpythonwin','win32com','shell','upackage=','uapp=','umodule=','description','examples'])
  537.         for arg in args:
  538.             searchPaths.append(arg)
  539.         for o,a in opts:
  540.             if o=='--description':
  541.                 print description
  542.             if o=='--examples':
  543.                 print examples
  544.             if o=='--shell':
  545.                 print "Registering the Python core."
  546.                 RegisterShellInfo(searchPaths)
  547.             if o=='--pythonwin':
  548.                 print "Registering Pythonwin"
  549.                 RegisterPythonwin(searchPaths)
  550.             if o=='--win32com':
  551.                 print "Registering win32com"
  552.                 RegisterWin32com(searchPaths)
  553.             if o=='--unpythonwin':
  554.                 print "Unregistering Pythonwin"
  555.                 UnregisterPythonwin()
  556.             if o=='-m':
  557.                 import os
  558.                 print "Registering module",a
  559.                 FindRegisterModule(os.path.splitext(a)[0],a, searchPaths)
  560.             if o=='--umodule':
  561.                 import os, regutil
  562.                 print "Unregistering module",a
  563.                 regutil.UnregisterModule(os.path.splitext(a)[0])
  564.             if o=='-p':
  565.                 print "Registering package", a
  566.                 FindRegisterPackage(a,None,searchPaths)
  567.             if o in ['--upackage', '--uapp']:
  568.                 import regutil
  569.                 print "Unregistering application/package", a
  570.                 regutil.UnregisterNamedPath(a)
  571.             if o=='-a':
  572.                 import regutil
  573.                 path = string.join(searchPaths,";")
  574.                 print "Registering application", a,"to path",path
  575.                 regutil.RegisterNamedPath(a,path)
  576.             if o=='-c':
  577.                 if not len(searchPaths):
  578.                     raise error, "-c option must provide at least one additional path"
  579.                 import win32api, regutil
  580.                 currentPaths = string.split(regutil.GetRegisteredNamedPath(None),";")
  581.                 oldLen = len(currentPaths)
  582.                 for newPath in searchPaths:
  583.                     if newPath not in currentPaths:
  584.                         currentPaths.append(newPath)
  585.                 if len(currentPaths)<>oldLen:
  586.                     print "Registering %d new core paths" % (len(currentPaths)-oldLen)
  587.                     regutil.RegisterNamedPath(None,string.join(currentPaths,";"))
  588.                 else:
  589.                     print "All specified paths are already registered."
  590.